package controller;
import io.ExportCSS;
import io.ExportImage;
import io.FileExtensionUtils;import io.FileSaveDialog;import java.io.File;import java.io.IOException;import model.Prescription;
import view.Designer;
import view.Toolbox;
/** * An event handler class for the menus of the designer * @author Daniel Bond, Mohammed Abdullah, Gideon Pyzer * */
public class MenuEventHandler extends EventHandler
{
	/**	 * Creates the appropriate event from a message passed to this method	 * @param the event object with the message needed to identify the behaviour required.	 */
	public void createEvent(CustomEvent event) 
	{
		Designer designer = Designer.getInstance();
		Prescription prescription = Prescription.getInstance();
		if (event.getName().equals("presNew")){
			if(designer.saveChanges(false))
			{
				prescription.clear();
				Toolbox.getInstance().resetToolbox();
				designer.switchLists(false);
				designer.setButtonsUsable();
				designer.update();				return;
			}			return;
		}
		if(event.getName().equals("presExportCSS")){
			FileSaveDialog fsd = FileSaveDialog.getInstance();			File selected = fsd.show();			if(selected != null){				String filename = selected.getPath();				ExportCSS.export(filename);				Prescription.getInstance().setUnchanged();				return;			}			return;
		}
		if (event.getName().equals("exit")){
			designer.exitApp();			return;
		}
		if (event.getName().equals("presExportImage")){
			try {				FileSaveDialog fsd = FileSaveDialog.getInstance();				File selected = fsd.show();				if(selected != null){					String selectedFilterExt = FileExtensionUtils.getExtension(selected);					ExportImage.export(selected, selectedFilterExt);					Prescription.getInstance().setUnchanged();					return;					}
			} catch (IOException e1) {
				e1.printStackTrace();
			}			return;
		}
		if (event.getName().equals("about")){			designer.showMessageDialog("Developed by Gideon Pyzer, Daniel Bond, Mohammad Abdullah & Marvin Crawford " +					"\r\n \u00a9 2010/11.  Prescription Designer", "About", 1);			return;
		}
	}
}